package com.ysqcould.web.controller.Community;


import com.ysqcould.Community.domain.DonationsActivity;
import com.ysqcould.Community.domain.vo.DoActivityVo;
import com.ysqcould.Community.service.IDonationsActivityService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 公益捐助二维码Controller
 * 
 * @author ruoyi
 * @date 2022-06-30
 */
@RestController
@RequestMapping("/Community/doActivity")
public class DonationsActivityController extends BaseController
{
    @Autowired
    private IDonationsActivityService donationsActivityService;

    /**
     * 查询公益捐助二维码列表
     */
    @PreAuthorize("@ss.hasPermi('Community:doActivity:list')")
    @GetMapping("/list")
    public TableDataInfo list(DonationsActivity donationsActivity)
    {
        startPage();
        List<DoActivityVo> list = donationsActivityService.selectDonationsActivityList(donationsActivity);
        return getDataTable(list);
    }

    /**
     * 导出公益捐助二维码列表
     */
    @PreAuthorize("@ss.hasPermi('Community:doActivity:export')")
    @Log(title = "公益捐助二维码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DonationsActivity donationsActivity)
    {
        List<DoActivityVo> list = donationsActivityService.selectDonationsActivityList(donationsActivity);
        ExcelUtil<DoActivityVo> util = new ExcelUtil<DoActivityVo>(DoActivityVo.class);
        util.exportExcel(response, list, "公益捐助二维码数据");
    }

    /**
     * 获取公益捐助二维码详细信息
     */
    @PreAuthorize("@ss.hasPermi('Community:doActivity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(donationsActivityService.selectDonationsActivityById(id));
    }

    /**
     * 新增公益捐助二维码
     */
    @PreAuthorize("@ss.hasPermi('Community:doActivity:add')")
    @Log(title = "公益捐助二维码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DonationsActivity donationsActivity)
    {
        donationsActivity.setAsId(getUserId());
        return toAjax(donationsActivityService.insertDonationsActivity(donationsActivity));
    }

    /**
     * 修改公益捐助二维码
     */
    @PreAuthorize("@ss.hasPermi('Community:doActivity:edit')")
    @Log(title = "公益捐助二维码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DonationsActivity donationsActivity)
    {
        return toAjax(donationsActivityService.updateDonationsActivity(donationsActivity));
    }

    /**
     * 删除公益捐助二维码
     */
    @PreAuthorize("@ss.hasPermi('Community:doActivity:remove')")
    @Log(title = "公益捐助二维码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(donationsActivityService.deleteDonationsActivityByIds(ids));
    }
}
